<?php
/*
 * 主要功能:
 *
 * dreamxyp(QQ:31996798) - PHP - class.review.php
 * coding:夏一平
 * 創建時間:2007-1-8
 */
 class review
 {
 	static public function qj2bj($string)
 	{
	     $qj2bj = array(
			'１' => '1', '２' => '2','３' => '3', '４' => '4', '５' => '5',
			'６' => '6', '７' => '7', '８' => '8', '９' => '9', '０' => '0',
			'ａ' => 'a', 'ｂ' => 'b', 'ｃ' => 'c', 'ｄ' => 'd', 'ｅ' => 'e',
			'ｆ' => 'f', 'ｇ' => 'g', 'ｈ' => 'h', 'ｉ' => 'i', 'ｊ' => 'j',
			'ｋ' => 'k', 'ｌ' => 'l', 'ｍ' => 'm', 'ｎ' => 'n', 'ｏ' => 'o',
			'ｐ' => 'p', 'ｑ' => 'q', 'ｒ' => 'r', 'ｓ' => 's', 'ｔ' => 't',
			'ｕ' => 'u', 'ｖ' => 'v', 'ｗ' => 'w', 'ｘ' => 'x', 'ｙ' => 'y',
			'ｚ' => 'z', 'Ａ' => 'A', 'Ｂ' => 'B', 'Ｃ' => 'C', 'Ｄ' => 'D',
			'Ｅ' => 'E', 'Ｆ' => 'F', 'Ｇ' => 'G', 'Ｈ' => 'H', 'Ｉ' => 'I',
			'Ｊ' => 'J', 'Ｋ' => 'K', 'Ｌ' => 'L', 'Ｍ' => 'M', 'Ｎ' => 'N',
			'Ｏ' => 'O', 'Ｐ' => 'P', 'Ｑ' => 'Q', 'Ｒ' => 'R', 'Ｓ' => 'S',
			'Ｔ' => 'T', 'Ｕ' => 'U', 'Ｖ' => 'V', 'Ｗ' => 'W', 'Ｘ' => 'X',
			'Ｙ' => 'Y', 'Ｚ' => 'Z', '　' => ' ', '，' => ',', '。' => '.',
			'？' => '?', '＜' => '<', '＞' => '>', '〔' => '[', '〕' => ']',
			'＊' => '*', '＆' => '&', '' => '^', '％' => '%', '＃' => '#',
			'＠' => '@', '！' => '!', '（' => '(', '）' => ')', '＋' => '+',
			'－' => '-', '｜' => '|', '：' => ':', '；' => ':', '點' => '.',
			'｛' => '{', '｝' => '}', '／' => '/', '〞' => '"', '＝' => '=',
			'×' => '',  '．' => '.',
			'零' => '0', '一' => '1', '二' => '2', '三' => '3', '四' => '4', 
			'五' => '5', '六' => '6', '七' => '7', '八' => '8', '九' => '9', 
			'壹' => '1', '貳' => '2', '三' => '3', '肆' => '4', '伍' => '5', 
			'陸' => '6', '柒' => '7', '捌' => '8', '玖' => '9', 
			'zero' 	=> '0', 'one' 	=> '1', 'two' 	=> '2', 'three' 	=> '3', 
			'four' 	=> '4', 'five' 	=> '5', 'six' 	=> '6', 'seven' 	=> '7', 
			'eight' => '8', 'nine' 	=> '9',
		);
		 //壹貳三肆伍陸柒捌玖zero,one,two,three,four,five,six,seven,eight,nine,yi,er,san,si,wu,liu,qi,ba,jiu,ling
		return strtr($string, $qj2bj);
	} 
	static public function bad_word($str)
	{
		$lines = @str_replace(chr(13),'',file_get_contents('bad_word.ini'));
		$regex = array(
			"/\[.+?\]/",
			"/[^0-9a-z".chr(0xa1)."-".chr(0xff)."]/",
			"/(　|、|。|·|¯|ˇ|‥|〃|々|～|∥|…|〔|〕|〈|〉|《|》|「|」|『|』|【|】|【|】|±|×|÷|︰|Λ|ˇ|Σ|Π|∪|∩|∈|∷|√|⊥|∥|∠|⌒|⊙|∫|∮|≡|≌|≒|∽|∝|≠|≮|≯|≤|≥|∞|∵|∴|♂|♀|°|′|〞|℃|＄|¤|￠|￡|‰|§|№|☆|★|○|●|◎|◇|◆|□|■|△|▲|※|→|←|↑|↓|═|Ⅰ|Ⅱ|Ⅲ|Ⅳ|Ⅴ|Ⅵ|Ⅶ|Ⅷ|Ⅸ|Ⅹ|⒈|⒉|⒊|⒋|⒌|⒍|⒎|⒏|⒐|⒑|⒒|⒓|⒔|⒕|⒖|⒗|⒘|⒙|⒚|⒛|１|２|３|４|５|６|７|８|９|十|⑾|⑿|⒀|⒁|⒂|⒃|⒄|⒅|⒆|⒇|１|２|３|４|５|６|７|８|９|十|一|二|三|四|五|六|七|八|九|十|Ⅰ|Ⅱ|Ⅲ|Ⅳ|Ⅴ|Ⅵ|Ⅶ|Ⅷ|Ⅸ|Ⅹ|Ⅺ|Ⅻ|！|〞|＃|￥|％|＆|′|（|）|＊|＋|，|－|．|／|０|１|２|３|４|５|６|７|８|９|：|；|＜|＝|＞|？|＠|Ａ|Ｂ|Ｃ|Ｄ|Ｅ|Ｆ|Ｇ|Ｈ|Ｉ|Ｊ|Ｋ|Ｌ|Ｍ|Ｎ|Ｏ|Ｐ|Ｑ|Ｒ|Ｓ|Ｔ|Ｕ|Ｖ|Ｗ|Ｘ|Ｙ|Ｚ|〔|＼|〕||ˍ|『|ａ|ｂ|ｃ|ｄ|ｅ|ｆ|ｇ|ｈ|ｉ|ｊ|ｋ|ｌ|ｍ|ｎ|ｏ|ｐ|ｑ|ｒ|ｓ|ｔ|ｕ|ｖ|ｗ|ｘ|ｙ|ｚ|｛|｜|｝|￣|Α|Β|Γ|Δ|Ε|Ζ|Η|Θ|Ι|Κ|Λ|Μ|Ν|Ξ|Ο|Π|Ρ|Σ|Τ|Υ|Φ|Χ|Ψ|Ω|α|β|γ|δ|ε|ζ|η|θ|ι|κ|λ|μ|ν|ξ|ο|π|ρ|σ|τ|υ|φ|χ|ψ|ω|ā|á|ǎ|à|ē|é|ě|è|ī|í|ǐ|ì|ō|ó|ǒ|ò|ū|ú|ǔ|ù|ǖ|ǘ|ǚ|ǜ|ü|ê|ㄅ|ㄆ|ㄇ|ㄈ|ㄉ|ㄊ|ㄋ|ㄌ|ㄍ|ㄎ|ㄏ|ㄐ|ㄑ|ㄒ|ㄓ|ㄔ|ㄕ|ㄖ|ㄗ|ㄘ|ㄙ|ㄚ|ㄛ|ㄜ|ㄝ|ㄞ|ㄟ|ㄠ|ㄡ|ㄢ|ㄣ|ㄤ|ㄥ|ㄦ|ㄧ|ㄨ|ㄩ|─|═|│|│|…|…|│|…|…|…|│|│|┌|┌|┌|┌|┐|┐|┐|┐|└|└|└|└|┘|┘|┘|┘|├|╞|├|├|├|├|├|├|┤|╡|┤|┤|┤|┤|┤|┤|┬|┬|┬|┬|┬|┬|┬|┬|┴|┴|┴|┴|┴|┴|┴|┴|┼|┼|┼|╪|┼|┼|│|┼|┼|┼|┼|┼|┼|┼|┼|┼)/",
			"/ +([a-z]{2,3})(i|o|e|vel)?([^a-z ])?/",
			"/([0-9a-z])[".chr(0xa1)."-".chr(0xff)."]{2,4}([0-9a-z])/",
			"/([".chr(0xa1)."-".chr(0xff)."])[0-9a-z]{1,2}([".chr(0xa1)."-".chr(0xff)."]){4,}/",
			"/ /",
		);
		$replace = array(
			" ",
			" ",
			" ",
			".\\1\\2\\3",
			"\\1 \\2",
			"\\1 \\2",
			"",
		);
		
		$count 	= 0;
		$str   	= urldecode($str);
		$str	= self::qj2bj($str);
		$str 	= preg_replace($regex,$replace,strtolower($str)." ");
		
		$comCount 	= substr_count($str, "dreamxyp(QQ:31996798)");
		$httpCount 	= substr_count($str, "http");
		//echo "str:".$str;
		str_replace(explode(chr(10),$lines),'',$str,$count);
		if($count)
		{
			//msg($count);
			return true;
		}else if(substr_count($str, ".com") != $comCount)
		{
			return true;
		}else if($httpCount != $comCount and $httpCount)
		{
			return true;
		}else
		{
			return false;
		}
	}
	//公共黑名單
	static public function g_bad_list($urs)
	{
		global $db;
		$lines 	= @explode(chr(10),str_replace(chr(13),'',file_get_contents('bad_urs.ini')));
		$ip 	= @explode(chr(10),str_replace(chr(13),'',file_get_contents('bad_ip.ini')));
		if(in_array($urs,$lines) or in_array(g::ip(),$ip))
		{
			return true;
		}elseif($urs == "56com")
		{
			return false;
		}else
		{
			$rsArray = $db->rsArray("select count(*) as cc from flv_comment_bad_user_list where badname= ? ",$urs);
			if($rsArray['cc'] >= 10)
			{ //10次處於黑名單即被系統禁言
				return true;
			}else
			{
				return false;
			}
		}
	}
	//用戶黑名單
	static public function u_bad_list($urs)
	{
		global $db;
		$sql = array(
			'myname' 	=> $_POST['date_urs'],
			'badname'	=> $urs
		);
		$rsCount = $db->rsArray("select badname from flv_comment_bad_user_list where myname=:myname and  badname=:badname ",$sql);
		if($rsCount)
		{
			return true;
		}else
		{
			return false;
		}
	}
	static public function clearCache($date_id='',$urs='')
	{
		if($date_id)dc::del($date_id,'did');
		if($urs)dc::del($urs,'uid');
	}	
	static public function cacheAdd($date_id,$urs,$data)
	{
		//ID
		$did = dc::get($date_id,3600*24,'did');
		if($did)
		{
			$did['count']++;
			//print_r($did);
			$did['data'] = array_merge(array($data),$did['data']);
			//print_r($did);
			dc::put($date_id,$did,'did');
		}else
		{
			dc::del($date_id,'did');
		}
		//用戶
		$uid = dc::get($urs,3600*72,'uid');
		if($uid)
		{
			$uid['count'] ++;
			$uid['data'] = array_merge(array($data),$uid['data']);
			dc::put($urs,$uid,'uid');
		}else
		{
			dc::del($urs,'uid');
		}
	}
	static public function read($mode,$key,$page=1,$rows=10,$pct='')
	{
		global $db;
		$page 	= $page<1 ? 1 : $page;
		$rs 	= array();
		switch($mode)
		{
			case 'flv';
				$rs = $db->rsArray("select count(*) as count from flv_comment_on where date_id=:data_id and pct in(:pct ,0) ",$key);
				$rs['data'] = $db->dataArray("select * from flv_comment_on where date_id=:data_id and pct in(:pct ,0) order by id desc limit ".($page*$rows-$rows).",".$rows." ",$key);
			break;
			case 'user';
				$rs = $db->rsArray("select count(*) as count from flv_comment_on where date_urs= ? ",$key);
				$rs['data'] = $db->dataArray("select * from flv_comment_on where date_urs= ?  order by id desc limit ".($page*$rows-$rows).",".$rows." ",$key);
			break;
			case 'user_only';
				$rs = $db->rsArray("select count(*) as count from flv_comment_on where date_urs= ? and date_id = 0 ",$key);
				$rs['data'] = $db->dataArray("select * from flv_comment_on where date_urs= ? and date_id = 0  order by id desc limit ".($page*$rows-$rows).",".$rows." ",$key);
			break;
			case 'review';
				$rs =$db->rsArray("select id,content from flv_comment_on where date_id=:data_id and pct in(:pct ,0) ",$key);
				if(empty($rs['content']))
				{
					$rs['content'] = '歡迎大家留言！和我成為好朋友！';
				}
			break;
			case 'me';
				$rs = $db->rsArray("select count(*) as count from flv_comment_on where name_id= ? ",$key);
				$rs['data'] = $db->dataArray("select * from flv_comment_on where name_id= ?  order by id desc limit ".($page*$rows-$rows).",".$rows." ",$key);
			break;
		}
		if($rs['data'])
		{
			foreach($rs['data'] as &$v)
			{
				$v['EnId'] = g::flvEnId($v['date_id']);
			}
		}
		return $rs;
	}
 }
?>
